﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellDynLibManager_h
#define CellDynLibManager_h

#include "CellPrerequisites.h"
#include "CellSingleton.h"

namespace cell
{
/** \addtogroup Core
 *  @{
 */
/** \addtogroup General
 *  @{
 */

/** 动态管理动态链接库的管理器。
@author
	Jiangwei Xu
@remarks
	该管理器追踪所有打开的动态链接库，维护每一个动态库的工作状态。
*/
class _CellExport DynLibManager: public Singleton<DynLibManager>, public DynLibAlloc
{
public:
	/** 默认构造函数。
	@note
		作为单件对象不能直接调用。该对象由 Nucleus 对象自动进行创建。
	@see
		Nucleus::Nucleus
	*/
	DynLibManager(void);

	/** 析构函数。
	@see
		Nucleus::~Nucleus
	*/
	virtual ~DynLibManager(void);

public:
	/** 加载动态库。
	@param
		filename 动态库文件名。可以省略文件扩展名。
	*/
	DynLib* load(const String& filename);

	/** 卸载动态库。
	@param
		lib 已经被加载的库句柄。
	*/
	void unload(DynLib* lib);

	/** 覆盖标准 Singleton 检索方法。
	*/
	static DynLibManager& getSingleton(void);
	/** 覆盖标准 Singleton 检索方法。
	*/
	static DynLibManager* getSingletonPtr(void);

protected:
	typedef HashMap<String, DynLib*> DynLibList;
	DynLibList mLibList;
};

/** @} */
/** @} */
} // end namespace cell

#endif // CellDynLibManager_h
